home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-02-07 | 10.2 KB | 251 lines | [TEXT/MPS ] |
- UNIT UProcessUtils;
-
- {-------------------------------------------------------------------------------
- #
- # Apple Macintosh Developer Technical Support
- #
- # Interfaces for the guts of the ProcDoggie application
- #
- # Program: ProcDoggie
- # File: UProcessUtils.p - Pascal Implementation
- #
- # by: Forrest Tanaka
- #
- # Copyright © 1988-1991 Apple Computer, Inc.
- # All rights reserved.
- #
- --------------------------------------------------------------------------------
- #
- # This unit is a high-level interface to the Process Manager. It contains
- # routines which allow you to launch a process, terminate a process, count the
- # number of open processes, find a process given a file specification, and
- # manage a list of documents for a process to open or print when it is
- # launched.
- #
- # The LaunchProcess routine is the most important routine in this unit. It
- # lets you launch either an application or a desk accessory and optionally lets
- # you pass it a list of documents for the launched application to open or print
- # (desk accessories don’t have document lists).
- #
- -------------------------------------------------------------------------------}
- {[j=20/57/1$] Pasmat Options}
-
-
- INTERFACE
-
-
- (*******************************************************************************
- * Used Units
- *******************************************************************************)
-
- USES
- (* Group 1 *)
- Types
- ,QuickDraw
-
- (* Group 2 *)
- ,AppleEvents
- ,Errors
- ,Events
- ,OSUtils
- ,Memory
- ,Resources
- ,SegLoad
-
- (* Group 3 *)
- ,Aliases
- ,Files
- ,Processes
- ;
-
-
- (*******************************************************************************
- * Types
- *******************************************************************************)
-
- TYPE
- (* Flag to indicate whether document list is for printing or opening *)
- LaunchModeCode = (kJustLaunch, kOpenLaunch, kPrintLaunch);
-
- (* Document list entry for opening apps with docs to open or print *)
- DocListEntryPtr = ^DocListEntryRec;
- DocListEntryHnd = ^DocListEntryPtr;
- DocListEntryRec = RECORD
- next: DocListEntryHnd; {Link to the next document list record}
- docFile: FSSpec {File specification}
- END;
-
- (* Document list for opening apps with docs to open or print *)
- DocListRec = RECORD
- docList: DocListEntryHnd; {Handle to the first document list entry}
- openPrint: LaunchModeCode {Opening or printing documents?}
- END;
- DocListPtr = ^DocListRec;
- DocListHnd = ^DocListPtr;
-
-
- (*******************************************************************************
- * CreateDocList - Create a new document list
- *
- * This routine creates a new document list and returns a handle to it. If there
- * isn’t enough memory for a new document list, CreateDocList returns NIL.
- *
- * If openOrPrint is kOpenLaunch, then the list of documents that are put into
- * the new document list will be opened when the application is launched. If
- * openOrPrint is kPrintLaunch, then the list of documents will be printed when
- * the application is launched. If kJustLaunch or any other value is passed in
- * openOrPrint, then no document list is created. CreateDocList returns NIL in
- * this case. This isn’t really a conflict with returning NIL when there’s not
- * enough memory for the new document list because the calling routine can check
- * to see if openOrPrint is valid or not itself.
- *******************************************************************************)
-
- FUNCTION CreateDocList (openOrPrint: LaunchModeCode): DocListHnd;
-
-
- (*******************************************************************************
- * IsEmptyDocList - Return TRUE if the specified document list is empty.
- *
- * IsEmptyDocList returns TRUE if the document list specified by "theList" is
- * empty. “Empty” can mean either that theList is NIL or theList is a handle to
- * a document list that contains no documents. It returns FALSE if there’s at
- * least one entry in "theList".
- *
- * theList must either be a valid handle to a document list or it must be NIL.
- * IsEmptyDocList is unpredictable if this isn’t true.
- *******************************************************************************)
-
- FUNCTION IsEmptyDocList (theList: DocListHnd): Boolean;
-
-
- (*******************************************************************************
- * AddToDocList - Add a document file specification to a document list
- *
- * AddToDocList adds the file specified by "newFile" to the end of the document
- * list specified by "theList". If there isn’t enough memory to add a new file
- * to the document list, then AddToDocList returns memFullErr. Otherwise, noErr
- * is returned.
- *
- * theList MUST be a valid handle to an initialized document list. I won’t be
- * responsible for AddToDocList’s actions if this isn’t true.
- *******************************************************************************)
-
- FUNCTION AddToDocList (newFile: FSSpec;
- theList: DocListHnd): OSErr;
-
-
- (*******************************************************************************
- * DisposeDocList - Dispose of a document list
- *
- * DisposeDocList deallocates all the memory occupied by the document list
- * specified by the "theList" parameter. If theList is NIL, then nothing is
- * done. If it’s not a valid DocListHnd, DisposeDocList is unpredictable.
- *******************************************************************************)
-
- PROCEDURE DisposeDocList (theList: DocListHnd);
-
-
- (*******************************************************************************
- * WereInFront - Test to see if this application is in front or not
- *
- * This routine determines whether this application is the front-most application
- * or not. If it is, then TRUE is returned. If it isn’t, then FALSE is
- * returned.
- *******************************************************************************)
-
- FUNCTION WereInFront: Boolean;
-
-
- (*******************************************************************************
- * FindProcess - Find a process with specified file and name
- *
- * FindProcess searches the Process Manager’s process list for a process that was
- * launched from the file specified by "testFile". If the process being searched
- * is a DA, then the "daName" parameter must specify the name of the desk
- * accessory (i.e. the name of the DRVR resource, including the initial null
- * character). If the process is found, then information about the process is
- * returned in the "testFileInfo" parameter, and FindProcess returns TRUE. If
- * the process could not be found, then FALSE is returned, and "testFileInfo" is
- * unchanged.
- *
- * Warning: the processName and processAppSpec fields of "testFileInfo" are NOT
- * valid when FindProcess returns TRUE. If the name and FSSpec of the found file
- * are desired, then the calling routine must allocate space for those fields
- * and call GetProcessInfo itself, passing the ProcessInfoRec returned by this
- * routine as a parameter.
- *******************************************************************************)
-
- FUNCTION FindProcess (testFile: FSSpec;
- daName: StringPtr;
- VAR testFileInfo: ProcessInfoRec): Boolean;
-
-
- (*******************************************************************************
- * LaunchProcess - Launch the specified process
- *
- * This routine launches the process whose file has the location and name
- * specified by "processFile" parameter. The process’s resulting serial number
- * is returned in the returnPSN parameter. If the process to be launched is a
- * desk accessory, then the name of the desk accessory (including the initial
- * null character that desk accessories require) is passed in daName. IF NIL is
- * passed in daName, then the first desk accessory found in the specified file
- * (according to the Resource Manager) is launched. If an application is being
- * launched, then daName is ignored. The options parameter specifies options to
- * use when launching the new process. It has the same values and meanings as
- * the LaunchFlags type defined in the Process Manager chapter of Inside
- * Macintosh VI. If a desk accessory is being launched, then only the
- * launchContinue flag has significance.
- *
- * A list of documents to be opened or printed by the launched application can
- * optionally be specified by the docList parameter. If no documents are
- * specified, then docList should be NIL. See the document list routines defined
- * early in this unit.
- *
- * LaunchProcess determines whether to launch an application or desk accessory
- * based on the type code of the file specified by processFile. If the file’s
- * type is APPL, then LaunchProcess attempts to launch it as an application. If
- * the file has any other type, then LaunchProcess attempts to launch a desk
- * accessory in that file.
- *
- * LaunchProcess returns two kinds of errors. One error is returned as a
- * function result. These kinds of errors are generated by any call that occurs
- * during the execution of LaunchProcess that is only used to manage the
- * launching of the specified application rather than launching the application
- * itself. The launchError parameter returns the error code of any error that
- * occurs when the application is actually launched.
- *******************************************************************************)
-
- FUNCTION LaunchProcess (processFile: FSSpec;
- daName: StringPtr;
- docList: DocListHnd;
- options: LaunchFlags;
- VAR returnPSN: ProcessSerialNumber;
- VAR launchError: OSErr): OSErr;
-
-
- (*******************************************************************************
- * CountProcesses - Count the number of open processes
- *
- * This routine searches through the Process Manager’s process list and counts
- * the number of open processes. The result is returned.
- *******************************************************************************)
-
- FUNCTION CountProcesses: Integer;
-
-
- (*******************************************************************************
- * TerminateProcess - Terminate a process
- *
- * This routine causes the process specified by "theProcessNum" to be terminated.
- * If an error occurs, then the error code is returned.
- *******************************************************************************)
-
- FUNCTION TerminateProcess (theProcessNum: ProcessSerialNumber): OSErr;
-
-
- IMPLEMENTATION
-
- {$I UProcessUtils.inc1.p}
-
- END.
-